package com.click.controller;

import com.click.common.Result;
import com.click.dto.WxLoginDTO;
import com.click.service.WxAuthService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.Map;

@Slf4j
@Validated
@RestController
@RequestMapping("/auth")
public class AuthController {
    
    @Autowired
    private WxAuthService wxAuthService;
    
    /**
     * 微信登录
     */
    @PostMapping("/wx-login")
    public Result<Map<String, Object>> wxLogin(@Valid @RequestBody WxLoginDTO wxLoginDTO) {
        log.info("微信登录请求: code={}", wxLoginDTO.getCode());
        
        Map<String, Object> result = wxAuthService.wxLogin(wxLoginDTO);
        return Result.success(result);
    }
    
    /**
     * 检查登录状态
     */
    @GetMapping("/check")
    public Result<Boolean> checkLogin(@RequestHeader(value = "Authorization", required = false) String token) {
        // 模拟token验证 - 将在M3安全模块中实现完整验证
        if (token == null || !token.startsWith("mock_token_")) {
            return Result.success(false);
        }
        return Result.success(true);
    }
    
    /**
     * 刷新token
     */
    @PostMapping("/refresh")
    public Result<String> refreshToken(@RequestHeader("Authorization") String token) {
        // 模拟token刷新 - 将在M3安全模块中实现完整逻辑
        return Result.success(token);
    }
}